<?php
/*
+----------------------------------------------------------------------+
| (c) Copyright Silkwires. 					                           |
| 	All Rights Reserved.                                               |
+----------------------------------------------------------------------+
| > Module: .........                                                  |
| > Author: (SW Team)  ........  					                   |
| >	Class description	: Defined data that is retrieved from database,| 
						  prepare some methods from base object        |
+----------------------------------------------------------------------+
*/

class User{
	
	private $db=null;
	private $config_site=null;
	
	function __construct(){
		$this->db=Zend_Registry::get('db');	
		$this->config_site=Zend_Registry::get('config_site');
	}
	
	function __destruct(){
		unset($this->db);
	}
	
	function insert($arrData){
	   $arrData ['created_time'] = date('Y-m-d H:i:s');
       $arrData ['updated_time'] = date('Y-m-d H:i:s');
		$rs=$this->db->insert('users',$arrData);
        
		return $this->db->lastInsertId('users');
	}
	function update ($arrData, $where){
	   
       $arrData['updated_time'] = date('Y-m-d H:i:s');
	   $rs = $this->db->update('users',$arrData, $where);
       return $rs;
	}
    function delete ($where){
	   
       //$arrData['updated_time'] = date('Y-m-d H:i:s');
	   $rs = $this->db->delete('users', $where);
       return $rs;
	}	
    /**
	 * Update Request Reset key to user
	 * @param $arrData
	 * @param $id
	 */
	function updateResetKey($arrData,$id){
		$rs=$this->db->update('users',$arrData,'id='.$id);
		return $rs;
	}
	/*function getListCity(){
        $query='SELECT * FROM city';
        $rs=$this->db->fetchAll($query);
        return $rs;
    }*/	
    function getListEmail($email){
        $query="SELECT * FROM users WHERE email = '$email'";
        $rs=$this->db->fetchAll($query);
        return $rs;
    }
	/**
	 * Get email from 
	 *
	 * @param string $username
	 * @return array $rs;
	 */
	function getEmailUser($email){

		$SQL="SELECT * FROM users WHERE email = ?";
        
		$rs=$this->db->fetchRow($SQL, array ($email));
        //var_dump($rs);
		return $rs;
	}
    
	function getUserById($user_id){
        $user_id=intval($user_id);
		$SQL="SELECT * FROM users WHERE id=?";
		$rs=$this->db->fetchRow($SQL, array ($user_id));
		return $rs;
	}    
}


?>